<template>
	<!-- 积分 -->
	<view class="content">
		<!-- 内容盒子 -->
		<!-- 积分信息 begin -->
		<view class="integral-info">
			<view class="info">
				<view class="val">420</view>
				<view class="title">积分</view>
			</view>
			<view class="info">
				<view class="val">3</view>
				<view class="title">排名</view>
			</view>
			<view class="detail" @click="goDetail">积分详情</view>
		</view>
		<!-- 积分信息 end -->
		<!-- 积分排名列表 begin -->
		<view class="content-item integral-ranking">
			<view class="header">
				<view class="title">考核积分排名</view>
			</view>
			<view class="sort">
				<picker mode="date" fields="year" @change="sortTimeChange">
					<view class="uni-input">{{ sortTime }}</view>
				</picker>
			</view>
			<view class="integral-ranking-info">
				<view class="tabbar">
					<view class="item" v-for="(item, index) in tabList" :key="index"
						:class="{ active: tabIndex === index }" @tap="switchTab(index)">
						{{ item }}
						<view class="underline" :style="{ border: tabIndex === index ? '2px solid #ad2325' : '0' }">
						</view>
					</view>
				</view>
				<swiper :current="tabIndex" :duration="300" :show-scrollbar="false"
					:style="{ height: swiperHeight + 'px' }">
					<swiper-item class="integral-list" v-for="(item, index) in tabList" :key="index">
						<view class="row">
							<view class="grid" v-for="item1 in 20">
								<view class="item">
									<view>{{ index + "-" + item1  }}</view>
									<image src="/static/img/mine/defalut-avatar.png" class="avatar"></image>
									<view class="user-info">
										<view class="name">李军</view>
										<view class="role">文化文史委员会</view>
									</view>
								</view>
								<view class="total-integral">
									<view class="title">总分</view>
									<view class="val">448</view>
								</view>
							</view>
						</view>
					</swiper-item>
				</swiper>
			</view>
		</view>
		<!-- 积分排名列表 end -->
	</view>

</template>

<script>
	const date = new Date();
	const sortTimeSuffix = "年";

	export default {
		data() {
			return {
				swiperHeight: 0,
				tabIndex: 0,
				tabList: [
					"履职排名",
					"我要填报",
				],
				sortTime: date.getFullYear() + sortTimeSuffix
			}
		},
		onLoad() {
			// this.boardcast = await this.$api('boardcast')
			this.$nextTick(() => {
				const query = uni.createSelectorQuery().in(this);
				query.select('.row').boundingClientRect((rect) => {
					if (rect && rect.height > 0) {
						this.swiperHeight = rect.height + 30 + 15;
					} else {
						console.error('Failed to get the container\'s bounding client rectangle');
					}
				}).exec();
			});
		},
		methods: {
			switchTab(index) {
				if (this.tabIndex === index) return;
				this.tabIndex = index;
			},
			sortTimeChange(e) {
				this.sortTime = e.detail.value + sortTimeSuffix;
			},
			goDetail() {
				this.$jump.toJump('pages/mine/integral-detail')
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		padding: 20rpx;
	}

	.integral-info {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 30rpx;
		background-image: url(@/static/img/mine/integral-info-bg.png);
		background-size: 100% 100%;

		.info {
			display: flex;
			flex-direction: column;
			align-items: center;
			margin-left: 10rpx;


			.val {
				font-size: 42rpx;
			}
		}

		.detail {
			display: flex;
			align-items: center;
			justify-content: center;
			height: 30rpx;
			background: #ad2325;
			font-size: 28rpx;
			color: #FFF;
			padding: 30rpx 40rpx;
			border-radius: 30rpx;
		}
	}


	.content-item {
		width: 100%;
		// padding: 20rpx 40rpx;
		margin: 30rpx 0;


		.header {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 20rpx;

			.title {
				font-size: $font-size-lg;
				font-weight: 500;
			}

			.subtitle {
				font-size: $font-size-base;
				color: $text-color-grey;
			}
		}
	}

	.integral-ranking {
		.sort {
			display: flex;
			justify-content: center;
			align-items: center;
			padding: 20rpx 0;
			background-color: $bg-color-white;
			border-radius: $border-radius-lg;
			font-weight: bold;
		}

		.integral-ranking-info {
			width: 100%;
			background-color: $bg-color-white;
			padding: 20rpx 40rpx;
			margin: 30rpx 0;
			border-radius: $border-radius-lg;

			.tabbar {
				display: flex;
				overflow-x: auto;
				white-space: nowrap;
				justify-content: space-around;
				-webkit-overflow-scrolling: touch;
				padding: 20rpx 0;

				.item {
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
					font-size: $font-size-lg;
					padding: 0 10rpx;
				}

				.underline {
					// background: none;
					// border: 2px solid #ad2325;
					border-radius: 0 0 50% 50% / 0 0 100% 100%;
					border-top: none !important;
					width: 40%;
					height: 16rpx;
					margin-top: 10rpx;
					// background: #ad2325;
					// border-radius: 15px
				}

				.active {
					color: #ad2325;
				}
			}
		}

		.row {
			display: flex;
			flex-wrap: wrap;
			padding: 10rpx;
			height: auto;

			.grid {
				display: flex;
				flex-direction: unset;
				align-items: start;
				justify-content: space-between;
				align-items: center;
				background: #fff;
				width: 100%;
				padding: 20rpx 0;
				border-radius: $border-radius-lg;
				border-bottom: 1rpx solid #c7c7c7;

				.item {
					display: flex;
					justify-content: space-between;
					align-items: center;

					.name {
						font-size: $font-size-lg;
					}

					.role {
						color: #ababab;
					}

					view {
						margin-right: 20px;
					}

					.avatar {
						margin-right: 20px;
					}
				}

				.total-integral {
					display: flex;
					align-items: center;

					.val {
						margin-left: 15rpx;
						font-size: $font-size-lg;
					}
				}

				image {
					width: 70rpx;
					height: 70rpx;
					border-radius: $border-radius-lg;
				}

				.title {
					margin-left: 20rpx;
				}
			}

			.grid:last-child {
				border-bottom: 0rpx solid #c7c7c7;

			}
		}
	}

	/deep/ .uni-scroll-view {
		height: auto;
	}

	/deep/ .uni-scroll-view-content {
		height: auto;
	}
</style>